Create .NET WEBSERVICE With Visual studio. Net Using
VB.NET, This example shows how web service returns a dataset.
Two Steps involved in Web Service
1)
How to Create a Web Service.
2)
How to Invoke Web Service.
How to Create a Web Service.
1) Open VisualStudio.Net
·
Select
File->New Project
Change location from http://localhost/webservice1
to http://localhost/mywebservice

Click
OK button, and the following screen provide the code editor and design screen
for web service.

Open the code editor by clicking the link “click here to switch the code view”. And copy the code from the file “mywebservice.asmx.vb”, save the file and Run the application. The “mywebservice” will be opened in the IE. Following screen shows you, the .asmx file and WSDL of mywebservice web service.


How to
Invoke Web Service.
To invoke a web
service that you have created just now, you have to create the proxy object . Follow the steps to create
the proxy object.
1)
From the command line run the following line.
C:\wsdl.exe /language:VB http://localhost/mywebservice/mywebservice.asmx?wsdl
The output of the above line is: mywebservice.vb file
which will be generated in the directory where wsdl.exe located.
2) Now we have to make “mywebservice.vb” file as
“mywebservice.dll”. To do this run the following command from the command line
c:\>vbc /t:library /r:System.Web.Wervices.dll
/r:System.xml.Serialization.dll /out:bin/mywebservice.dll mywebservice.vb.
Or
Step 2 can also be done from
visualstudio.net.
Open Visual studio.net and open File-> Project. (Select
class library from templates section) and change the name to mywebservice.

click “OK” Button and attach the file “mywebservice.vb”
to the project or
change the name of “class1.vb” to “mywebservice.vb” and
paste the code from “mywebservice.vb” file.
Add “System.Web.Services.dll” reference “Project -> Add
reference “ to the project (as shown in following fig.).

And build the project from (Build->Build Solution).
When you build the solution The assembly “mywebservice.dll” file will be
created in c:\myvbnet\myws\bin directory.
Open Visualstudio.net and create new ASP.net web
application as shown in following screen. Change the location name to http://www/localhost/testmywebservice
from http://www.localhost/webapplication1

Click OK button and from the menu (Project -> Add web
reference) and the following screen will be provided to enter the reference url
of web service we created. In the address bar type http://localhost/mywebservice/mywebservice.asmx
and press enter. And at the bottom of the screen click the “Add Reference”
button.

From the solution explorer expand references and right click the mouse and click the Add References.

and the following screen will be provided to add the mywebservice.dll to the asp.net project by clicking the browse button.

Click ok button and add the code from “webform1.aspx” file to the webform1.aspx and run the application. The following screen shows the output in browser.
